import typescript from 'rollup-plugin-typescript2'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import path from 'path'
import vue from 'rollup-plugin-vue'
// 解决一些老包的问题
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import babel from 'rollup-plugin-babel'

const extensions = ['.mjs', '.ts', '.js', '.tsx']
export default {
  input: path.resolve(__dirname, `../packages/index/index.ts`),
  output: {
    format: 'es',
    file: `lib/index.esm.js`,
  },
  plugins: [
    terser(),
    nodeResolve(),
    vue({
      target: 'browser',
    }),
    commonjs(),
    typescript({ // 默认调用tsconfig.json  帮我们生成声明文件
      tsconfigOverride:{
        compilerOptions: { // 打包单个组件的时候生成ts声明文件
          declaration: true,
        },
        exclude: [
          'node_modules',
          'website',
        ],
      },
    }),
    babel({
      exclude: 'node_modules/**',
      runtimeHelpers: true,
      extensions,
    }),
  ],
  external(id) { // 排除vue本身
    return /^vue/.test(id) || /^element-plus/.test(id)
  },
}
